FROM docker.jianmuhub.com/library/debian:bookworm-slim

# 设置环境变量
ENV DEBIAN_FRONTEND=noninteractive

###################################
# 安装基础依赖和PowerShell
###################################

RUN apt-get update && \
    apt-get install -y wget && \
    . /etc/os-release && \
    wget -q https://packages.microsoft.com/config/debian/$VERSION_ID/packages-microsoft-prod.deb && \
    dpkg -i packages-microsoft-prod.deb && \
    rm packages-microsoft-prod.deb && \
    apt-get update && \
    apt-get install -y powershell && \
    apt-get clean && \
    rm -rf /var/lib/apt/lists/*

###################################
# 安装PowerCLI
###################################

RUN wget -O /tmp/powercli.zip "https://dp-downloads.broadcom.com/?file=VCF-PowerCLI-9.0.0-24798382.zip&oid=442876&id=OZgaJoqfCI3Wpz2t8J2WkSzKk4ubG2lanBfLyjgulKL_j17x02A0iP4lzxAEU2E=&specDownload=true&verify=1761103371-oKq2%2F6%2FW3ydK2aPnYzbcauNGhfvMEbvgxNoEz8Yxd%2FY%3D"

# # 安装脚本
# RUN cat > /tmp/install-offline.ps1 << 'EOF'
# # 获取模块路径
# $modulePath = ($env:PSModulePath -split ':')[0]

# Write-Host "解压PowerCLI到: $modulePath" -ForegroundColor Yellow

# # 解压zip文件
# Expand-Archive -Path "/tmp/powercli.zip" -DestinationPath $modulePath -Force

# # 取消阻止文件
# Write-Host "取消阻止文件..." -ForegroundColor Yellow
# Get-ChildItem $modulePath -Recurse | Unblock-File

# # 验证安装
# Write-Host "验证安装..." -ForegroundColor Yellow
# Get-Module -Name VCF.PowerCLI -ListAvailable

# Write-Host "PowerCLI离线安装完成!" -ForegroundColor Green

# EOF

# 使用echo创建安装脚本（避免heredoc问题）
RUN echo '$modulePath = ($env:PSModulePath -split ":")[0]' > /tmp/install-offline.ps1 && \
    echo 'Write-Host "解压PowerCLI到: $modulePath" -ForegroundColor Yellow' >> /tmp/install-offline.ps1 && \
    echo 'Expand-Archive -Path "/tmp/powercli.zip" -DestinationPath $modulePath -Force' >> /tmp/install-offline.ps1 && \
    echo 'Write-Host "取消阻止文件..." -ForegroundColor Yellow' >> /tmp/install-offline.ps1 && \
    echo 'Get-ChildItem $modulePath -Recurse | Unblock-File' >> /tmp/install-offline.ps1 && \
    echo 'Write-Host "验证安装..." -ForegroundColor Yellow' >> /tmp/install-offline.ps1 && \
    echo 'Get-Module -Name VCF.PowerCLI -ListAvailable' >> /tmp/install-offline.ps1 && \
    echo 'Write-Host "PowerCLI离线安装完成!" -ForegroundColor Green' >> /tmp/install-offline.ps1

# 执行安装
RUN pwsh -File /tmp/install-offline.ps1

# 清理
RUN rm -f /tmp/powercli.zip /tmp/install-offline.ps1

#复制脚本文件
ADD script/* /tmp/

WORKDIR /tmp/
CMD ["pwsh"]
